package com.scp.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class Util {

	private static final String CNT_TAG_LOG = "LOG";
	
	public static String Estados[] = new String[] {"AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO"};
	
	public static void ToastLong(Context context, String text) {
		Toast.makeText(context, text, Toast.LENGTH_LONG).show();
	}
	public static void ToastShort(Context context, String text) {
		Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
	}
	
	public static void LogInfo(String msg) {
		Log.i(CNT_TAG_LOG, msg);
	}
	public static void LogError(String msg) {
		Log.e(CNT_TAG_LOG, msg);
	}
	public static void LogWarn(String msg) {
		Log.w(CNT_TAG_LOG, msg);
	}
	public static void LogDebug(String msg) {
		Log.w(CNT_TAG_LOG, msg);
	}
	
	public static Date stringToDate(String data) {
		return stringToDate(data, "dd/MM/yyyy");
	}
	
	public static Date stringToDate(String data, String formato) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(formato, Locale.getDefault());
		Date dataAux = null;
		try {
			dataAux = dateFormat.parse(data);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dataAux;
	}
	
	public static String dateToString(Date date) {
		return dateToString(date, "dd/MM/yyyy");
	}
	
	public static String dateToString(Date date, String formato) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(formato, Locale.getDefault());
		return dateFormat.format(date);
	}
	
	public static Date dataAtual() {
		Calendar calendar = Calendar.getInstance();			
		return calendar.getTime();
	}
	
	public static Date getDateTime(Date data, int hora, int minuto, int segundo) {
		Calendar calendar = Calendar.getInstance();		
		calendar.setTime(data);
		calendar.set(Calendar.HOUR, hora);
		calendar.set(Calendar.MINUTE, minuto);
		calendar.set(Calendar.SECOND, segundo);
		
		return calendar.getTime();
	}
	
	public static Date dataVazia() {
		Calendar calendar = Calendar.getInstance();		
		calendar.set(Calendar.YEAR, 1900);
		calendar.set(Calendar.MONTH, Calendar.JANUARY);
		calendar.set(Calendar.DATE, 1);
		
		calendar.set(Calendar.HOUR, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		
		return calendar.getTime();
	}

	public static int getHour(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.HOUR_OF_DAY);
	}
	
	public static int getMinute(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.MINUTE);
	}
		
}
